/**
 * 商户基础信息
 */
import apiUrl from "@/config/settings";
import Api from "@/api";

export default {
  namespaced: true,
  state: {
    shopId: uni.getStorageSync("shopId") || apiUrl.config.shop_id,
    sessionId: uni.getStorageSync("sessionId") || "",
    shop: {
      name: "",
      logo: "",
    },
  },
  mutations: {
    setShopId: (state, shopId) => {
      state.shopId = shopId;
      uni.setStorageSync("shopId", shopId);
    },
    // sessionId同步store
    getSessionIdToStore: (state, sessionId) => {
      state.sessionId = sessionId;
      uni.setStorageSync("sessionId", sessionId);
    },
  },
  actions: {
    // 用户登录_获取初始化数据
    getShopInit({ commit, dispatch, state }, params = {}) {
      return new Promise((resolve, reject) => {});
    },
    // 获取sessionId
    getSessionId({ commit, dispatch, state }) {
      Api.account.getSessionId().then((res) => {
        commit("getSessionIdToStore", res.session_id);
      });
    },
  },
};
